package com.specter.mvc.model;

import java.util.Collections;
import java.util.List;

import lombok.Data;

/**
 * 分页对象
 * 
 * @author Liang.Wang
 * @since 2010-11-23 下午02:06:22
 * @version 1.0
 */
@Data
public class Page<T> implements java.io.Serializable {
	private static final long serialVersionUID = 1L;
	
	/** 当前页码 */
	private long pageno;
	/** 总页数 */
	private long pageCount;
	/** 每页概述 */
	private Object sumup;
	/** 每页条数 */
	private long limit = 15L;
	/** 当前记录数 */
	private long rowno;
	/** 总记录条数 */
	private long rowCount;
	/** 总结果集合 */
	private List<T> rows;

	public Page(long pageno, long limit, long rowCount) {
		this.rowCount = rowCount;
		this.rowno = (pageno - 1) * limit;
		this.limit = limit;
		this.pageCount = (rowCount + limit - 1) / limit;
		this.pageno = pageno < 1 ? 1 : pageno;
		this.pageno = pageno > pageCount ? pageCount : pageno;

		this.rows = Collections.emptyList();
	}

	public Page(long pageno, long limit, long rowCount, List<T> rows) {
		this.rowCount = rowCount;
		this.rowno = (pageno - 1) * limit;
		this.limit = limit;
		this.pageCount = (rowCount + limit - 1) / limit;
		this.pageno = pageno < 1 ? 1 : pageno;
		this.pageno = pageno > pageCount ? pageCount : pageno;

		this.rows = rows;
	}
}
